

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" href="/img/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Cheney">
  <meta name="keywords" content="Coding">
  
    <meta name="description" content="验证全国其他省会城市（不包括港澳和两个宝岛台北和海口）到武汉中间不超过 2 个省（省会城市）是否成立？允许用户查询从任一个城市到另一个城市之间的最短路径。求解两个城市间的前第 K 短的路径 ？">
<meta property="og:type" content="article">
<meta property="og:title" content="交通咨询系统">
<meta property="og:url" content="https://cheney822.gitee.io/2020/12/09/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E8%AF%BE%E8%AE%BE--%E4%BA%A4%E9%80%9A%E5%92%A8%E8%AF%A2%E7%B3%BB%E7%BB%9F%E8%AE%BE%E8%AE%A1/index.html">
<meta property="og:site_name" content="Cheney blog">
<meta property="og:description" content="验证全国其他省会城市（不包括港澳和两个宝岛台北和海口）到武汉中间不超过 2 个省（省会城市）是否成立？允许用户查询从任一个城市到另一个城市之间的最短路径。求解两个城市间的前第 K 短的路径 ？">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/7bb6a2b6337c49d8ac91ac2618b40336-20220405210353482.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/8fe6974243d8440787fa12ab57f14854-20220405210353523.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/0c0016078650499d8ee80775ff9e4fe6-20220405210353590.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/dc6f161bd5b0449cb6e3dcaf5fa64d4f-20220405210353637.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/6638c20af958464cb9c24fc7f59a7ec2-20220405210353681.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/9a526f8b29264287be3e1be181286c2b-20220405210353726.png">
<meta property="og:image" content="https://imgbed.cheney.cc/picgo/8ee77e91fce840489893a0c6e53db096-20220405210353769.png">
<meta property="article:published_time" content="2020-12-09T05:14:00.000Z">
<meta property="article:modified_time" content="2022-04-05T13:14:27.871Z">
<meta property="article:author" content="Cheney">
<meta property="article:tag" content="C++">
<meta property="article:tag" content="图">
<meta property="article:tag" content="Dijkstra">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://imgbed.cheney.cc/picgo/7bb6a2b6337c49d8ac91ac2618b40336-20220405210353482.png">
  
  
  <title>交通咨询系统 - Cheney blog</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"cheney822.gitee.io","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":1},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Cheney Blog</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('https://imgbed.cheney.cc/Blog_config/default.png') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="交通咨询系统">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-09 13:14" pubdate>
        2020年12月9日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      8.9k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      45 分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">交通咨询系统</h1>
            
            <div class="markdown-body">
              <h1 id="一、问题描述："><a href="#一、问题描述：" class="headerlink" title="一、问题描述："></a>一、问题描述：</h1><p>交通咨询系统设计</p>
<h2 id="设计目的："><a href="#设计目的：" class="headerlink" title="设计目的："></a>设计目的：</h2><div class="code-wrapper"><pre><code class="hljs">熟练掌握迪杰斯特拉算法和费洛伊德算法，能够利用它们解决最短路径问题。
掌握图的深度，广度遍历算法。
掌握快速排序算法。
</code></pre></div>
<h2 id="内容："><a href="#内容：" class="headerlink" title="内容："></a>内容：</h2><p>设计一个交通咨询系统，通过读取<a target="_blank" rel="noopener" href="http://pan.baidu.com/s/1jIauHSE">全国城市距离图</a>（<a target="_blank" rel="noopener" href="http://pan.baidu.com/s/1jIauHSE%EF%BC%8C%E8%AF%B7%E5%9C%A8%E7%A8%8B%E5%BA%8F%E8%BF%90%E8%A1%8C%E6%97%B6%E5%8A%A8%E6%80%81%E5%8A%A0%E8%BD%BD%E5%88%B0%E5%86%85%E5%AD%98%EF%BC%8C%E5%8F%AF%E5%B0%86">http://pan.baidu.com/s/1jIauHSE，请在程序运行时动态加载到内存，可将</a> excel 转成 csv 方便读取），<br>实现：</p>
<ul>
<li>1、请验证全国其他省会城市（不包括港澳和两个宝岛台北和海口）到武汉中间不超过 2 个省（省会城市）是否成立？（正是因为武汉处于全国的中心位置，此次疫情才传播的如此广）；</li>
<li>2、允许用户查询从任一个城市到另一个城市之间的最短路径（两种算法均要实现，界面上可自行选择）<br>以及所有不重复的可行路径（可限制最多经过 10 个节点），<br>，每一条结果均需包含路径信息及总长度，试比较排序后的结果与迪杰斯特拉算法和费洛伊德算法输出的结果；</li>
<li>3、假设在求解 2 个城市间最短路径时需要绕过某个特定的城市（用户输入或者选择，例如<br>武汉），请问应该如何实现？</li>
<li>4、不基于功能 2 遍历的结果如何直接求解两个城市间的前第 K 短的路径，例如，武汉到北<br>京之间第 3 短的路径。</li>
</ul>
<h1 id="二、需求分析："><a href="#二、需求分析：" class="headerlink" title="二、需求分析："></a>二、需求分析：</h1><p>首先需要读写文件，注意给定的格式。</p>
<p>在验证到其他城市武汉中间不超过 2 个省时，新建一个二维数组将原二维数组中的权值全部改为1，这样用dijkstra算法得到的权值最小的路径就经过节点最少的路径。</p>
<p>需要绕过某个城市时，只需要新建一个二维数组将原二维数组中的与该城市有关的边的信息全部删除（权值全部改为0）即可。</p>
<p>求解两个城市前K短路径不能直接调用前述的结果，需要设计新的算法直接求解。</p>
<h1 id="三、概要设计："><a href="#三、概要设计：" class="headerlink" title="三、概要设计："></a>三、概要设计：</h1><h2 id="1、数据结构定义："><a href="#1、数据结构定义：" class="headerlink" title="1、数据结构定义："></a>1、数据结构定义：</h2><p>程序中的城市信息主要用图来存储，图类的定义如下：<br><strong>“无向图”CC_Group类的构建：</strong><br>数据成员有：</p>
<blockquote>
<p>int C_Adj[MaxSize][MaxSize];<br>int C_Visited[MaxSize];<br>int C_PointNum;//顶点数<br>int C_ArcNum;//边数</p>
</blockquote>
<p>C_Adj数组用来存储边的信息，C_Adj[i][j]不为零表示存在边（i，j）且这条边上的权值为C_Adj[i][j]的值。<br>C_Visited[i]用来存储节点是否被访问标记，为0则未标记，为1则已经被标记。默认全部为零。<br>C_Point表示当前图中的节点数<br>C_ArcNum表示当前图中的边数<br>对图的初始化是用文件来完成的：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><div class="code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></div></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//读文件 初始化图</span><br><span class="hljs-function"><span class="hljs-type">void</span> <span class="hljs-title">CC_Graph::CreateByFile</span><span class="hljs-params">(<span class="hljs-type">int</span>* PointNum, <span class="hljs-type">int</span>* arcNum, <span class="hljs-type">int</span>* C_BLoc, <span class="hljs-type">int</span>* C_ELoc)</span> </span>&#123;<br>    <br>    <span class="hljs-built_in">CC_File2</span>();<span class="hljs-comment">//用文件构造图</span><br>    *PointNum = <span class="hljs-number">34</span>;<br>    <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; i &lt; *PointNum; i++) &#123;<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> j = <span class="hljs-number">0</span>; j &lt; *PointNum; j++)<br>           <span class="hljs-keyword">if</span>(FilePath[i+<span class="hljs-number">1</span>][j+<span class="hljs-number">1</span>]==<span class="hljs-number">0</span>)&#123;<span class="hljs-comment">//无连接</span><br>               C_Adj[i][j] = <span class="hljs-number">0</span>;<br>           &#125;<br>           <span class="hljs-keyword">else</span>&#123;<br>               C_Adj[i][j] = FilePath[i + <span class="hljs-number">1</span>][j + <span class="hljs-number">1</span>];<br>           &#125;<br>    &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p>第二个功能中的所有路径是用链表作为存储结构的，每个链表存储一条路径：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">typedef</span> <span class="hljs-keyword">struct</span> <span class="hljs-title class_">LinkList</span><br>&#123;<br>    <span class="hljs-type">int</span> Data = <span class="hljs-number">-999</span>;<br>    LinkList* next = <span class="hljs-literal">NULL</span>;<br>&#125;LinkList;<br>LinkList* CCListHead[MaxNum] ;<br>LinkList* Current = <span class="hljs-keyword">new</span> LinkList;<br><span class="hljs-type">int</span> PathNum=<span class="hljs-number">0</span>;<span class="hljs-comment">//路径数目</span><br><span class="hljs-type">int</span> A[MaxNum];<span class="hljs-comment">//用于排序</span><br></code></pre></td></tr></table></figure>

<h2 id="2、模块设计："><a href="#2、模块设计：" class="headerlink" title="2、模块设计："></a>2、模块设计：</h2><p>主程序模块：主函数设计如下：<br>首先创建一个图类的对象并用文件初始化它。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><code class="hljs cpp"> <span class="hljs-type">int</span> PointNum = <span class="hljs-number">0</span>, arcNum = <span class="hljs-number">0</span>, C_BLoc = <span class="hljs-number">0</span>, C_ELoc = <span class="hljs-number">0</span>;<br><span class="hljs-comment">//   CC_Graph G(&amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc);//输入参数构造图</span><br>   CC_Graph G;<br>   G.<span class="hljs-built_in">CreateByFile</span>(&amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc);<br></code></pre></td></tr></table></figure>

<p>随后是一个循环，退出条件是进入0号功能，其他功能都有对应的function，涉及到的函数调用均在对应的function中。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">switch</span> (choice) <br>    &#123;<br>    <span class="hljs-keyword">case</span> <span class="hljs-number">0</span>: &#123;<br>        <span class="hljs-built_in">system</span>(<span class="hljs-string">&quot;cls&quot;</span>);<br>        cout &lt;&lt; <span class="hljs-string">&quot;\n\n\nThank You \n\n\n&quot;</span>;<br>        <span class="hljs-keyword">return</span> <span class="hljs-number">0</span>;<br>    &#125;<br>    <span class="hljs-keyword">case</span> <span class="hljs-number">1</span>: &#123;<br>        <span class="hljs-built_in">function1</span>(G, &amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc); <br>        <span class="hljs-keyword">break</span>; &#125;<br>    <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>: &#123;<br>        <span class="hljs-built_in">function2</span>( G,&amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc);<br>        <span class="hljs-keyword">break</span>; &#125;<br>    <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>: &#123;<br>        <span class="hljs-built_in">function3</span>(G, &amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc); <br>        <span class="hljs-keyword">break</span>; &#125;<br>    <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>: &#123;<br>        <span class="hljs-built_in">function4</span>(G, &amp;PointNum, &amp;arcNum, &amp;C_BLoc, &amp;C_ELoc);<br>        <span class="hljs-keyword">break</span>; &#125; <br>    &#125;<span class="hljs-comment">//switch结束</span><br></code></pre></td></tr></table></figure>


<p>Dijkstra:设置Visited[]保存是否被标记，Dis[]保存用户起点到下标号的节点路径的长度，Father[]保存最短路径上的前一个节点。<br><strong>算法主体有三步：</strong></p>
<ul>
<li><p>1更新：找到这样的两个顶点 即 i位置已经被访问 且j位置未被访问 且ij有连接，把(0,i)+（i，j）和(0,j)中的较小者赋给j，并且Father[j] = i即i作为j的前驱节点。</p>
</li>
<li><p>2访问：每轮在更新Dis后 判断最小未被标记的顶点 对其访问（vis = 1;）</p>
</li>
<li><p>重复1、2 步骤直到Visited[]的值全为1为止。</p>
</li>
</ul>
<h2 id="3、各模块间的调用关系："><a href="#3、各模块间的调用关系：" class="headerlink" title="3、各模块间的调用关系："></a>3、各模块间的调用关系：</h2><p><img src="https://imgbed.cheney.cc/picgo/7bb6a2b6337c49d8ac91ac2618b40336-20220405210353482.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<h1 id="四、详细设计"><a href="#四、详细设计" class="headerlink" title="四、详细设计"></a>四、详细设计</h1><p>主要算法设计：</p>
<h2 id="求最短路径Dijkstra算法的实现："><a href="#求最短路径Dijkstra算法的实现：" class="headerlink" title="求最短路径Dijkstra算法的实现："></a>求最短路径Dijkstra算法的实现：</h2><p>设置Visited[]保存是否被标记，Dis[]保存用户起点到下标号的节点路径的长度，Father[]保存最短路径上的前一个节点。其他类似于Prim算法。<br>算法主体有三步：</p>
<ul>
<li>1.更新：找到这样的两个顶点 即 i位置已经被访问 且j位置未被访问 且ij有连接，把(0,i)+（i，j）和(0,j)中的较小者赋给j，并且Father[j] = i即i作为j的前驱节点。    </li>
<li>2.访问：每轮在更新Dis后 判断最小未被标记的顶点 对其访问（vis = 1;）</li>
<li>3.重复1、2 步骤直到Visited[]的值全为1为止。</li>
</ul>
<p>然后是输出语句：</p>
<ol>
<li>输出用户输入位置到其他各个顶点的最短路径长度：<br>直接一个循环输出Dis数组的前n位即可</li>
<li>输出用户输入位置到其他各个顶点的最短路径对应的路线：<br>首先设置i从0到n的循环每次都将i赋值给VVV作为终点，v是用户输入的起点位置。</li>
</ol>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">while</span> (Father[vvv] != <span class="hljs-number">-1</span> &amp;&amp; Father[vvv] != v)<br>    &#123;<br>        cout &lt;&lt; Father[vvv] &lt;&lt; <span class="hljs-string">&quot;&lt;--&quot;</span>;<br>        vvv = Father[vvv];<br>    &#125;<br></code></pre></td></tr></table></figure>

<p>根据Father数组内存的节点的前驱关系输出路线。<br>以上是迪杰斯特拉算法的基础部分，</p>
<p>在本程序中由于多次调用了此算法，为了减少重复的代码提高代码的复用性，于是在此算法中增加了一个接口，即一个switch case开关语句，调用迪杰斯特拉时需要在参数列表中给出需要进入的部分以实现不同的功能。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">switch</span> (choice)<span class="hljs-comment">//不同的函数调用本函数时 进入不同的接口</span><br>   &#123;<br>   <span class="hljs-keyword">case</span> <span class="hljs-number">0</span>: &#123;<span class="hljs-keyword">break</span>; &#125;<br><br>   <span class="hljs-keyword">case</span> <span class="hljs-number">2</span>: &#123;<br><br>       cout &lt;&lt; <span class="hljs-string">&quot;\n&quot;</span> &lt;&lt; City[BLoc] &lt;&lt; <span class="hljs-string">&quot;到&quot;</span> &lt;&lt; City[ELoc] &lt;&lt; <span class="hljs-string">&quot;的最短路径长度为：&quot;</span> &lt;&lt; Dis[ELoc];<br>       cout &lt;&lt; <span class="hljs-string">&quot;   轨迹为：&quot;</span>;<br>       <span class="hljs-type">int</span> E = ELoc;<br>       cout &lt;&lt; City[E] &lt;&lt; <span class="hljs-string">&quot;&lt;--&quot;</span>;<br>       <span class="hljs-keyword">while</span> (Father[E] != <span class="hljs-number">-1</span> &amp;&amp; Father[E] != BLoc)<br>       &#123;<br>           cout &lt;&lt; City[Father[E]] &lt;&lt; <span class="hljs-string">&quot;&lt;--&quot;</span>;<br>           E = Father[E];<br>       &#125;<br>       cout &lt;&lt; City[BLoc];<br>       <span class="hljs-keyword">break</span>;<br>   &#125;<br>   <span class="hljs-keyword">case</span> <span class="hljs-number">3</span>: &#123;<span class="hljs-keyword">break</span>; &#125;<br>   <span class="hljs-keyword">case</span> <span class="hljs-number">4</span>: &#123;<span class="hljs-comment">//用于A*算法</span><br>  <br>       <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; i &lt; n; i++) <br>           dis[i] = Dis[i];<br>       <br>       <span class="hljs-keyword">break</span>; &#125;<br>   &#125;<br></code></pre></td></tr></table></figure>



<h2 id="CC-Floyd："><a href="#CC-Floyd：" class="headerlink" title="CC_Floyd："></a>CC_Floyd：</h2><ul>
<li>1，从任意一条单边路径开始。所有两点之间的距离是边的权，如果两点之间没有边相连，则权为无穷大。</li>
<li>2，对于每一对顶点 u 和 v，看看是否存在一个顶点 w 使得从 u 到 w 再到 v 比已知的路径更短。如果是更新它。</li>
</ul>
<p>把图用邻接矩阵G表示出来，如果从Vi到Vj有路可达，则G[i][j]=d，d表示该路的长度；否则G[i][j]=无穷大。<br>定义一个矩阵D用来记录所插入点的信息，D[i][j]表示从Vi到Vj需要经过的点，初始化D[i][j]=j。把各个顶点插入图中，比较插点后的距离与原来的距离，G[i][j] = min( G[i][j], G[i][k]+G[k][j] )，如果G[i][j]的值变小，则D[i][j]=k。<br>在G中包含有两点之间最短道路的信息，而在D中则包含了最短通路径的信息。<br>比如，要寻找从V5到V1的路径。根据D，假如D(5,1)=3则说明从V5到V1经过V3，路径为{V5,V3,V1}，如果D(5,3)=3，说明V5与V3直接相连，如果D(3,1)=1，说明V3与V1直接相连。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs cpp">Cway[i][j] = k;<span class="hljs-comment">//表示i到j的最短路径为i-&gt;k-&gt;j</span><br><span class="hljs-keyword">if</span> (Cpath[i][k] + Cpath[k][j] &lt; Cpath[i][j])<span class="hljs-comment">//如果插入中间节点后的路径长度比原来短 </span><br>&#123;<br>Cpath[i][j] = Cpath[i][k] + Cpath[k][j];<span class="hljs-comment">//修改路径为两半路径之和</span><br>Cway[i][j] = k;<span class="hljs-comment">//表示i到j的最短路径为i-&gt;k-&gt;j</span><br>&#125;<br></code></pre></td></tr></table></figure>

<p>与迪杰斯特拉算法类似本程序中也多次调用了Floyd算法，所以也类似的设计一个接口：</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">case</span> <span class="hljs-number">2</span>: &#123;<span class="hljs-comment">//输出AB两座城市</span><br><br>    cout &lt;&lt; <span class="hljs-string">&quot;\n&quot;</span> &lt;&lt; City[BLoc] &lt;&lt; <span class="hljs-string">&quot;到&quot;</span> &lt;&lt; City[ELoc] &lt;&lt; <span class="hljs-string">&quot;的最短路径长度为：&quot;</span> &lt;&lt; Cpath[BLoc][ELoc];<br>    cout &lt;&lt; <span class="hljs-string">&quot;   轨迹为：&quot;</span>;<br>    <span class="hljs-type">int</span> u = BLoc;<span class="hljs-comment">//起点</span><br>    <span class="hljs-keyword">while</span> (Cway[u][ELoc] != <span class="hljs-number">-1</span>) &#123;<span class="hljs-comment">//有中间节点就把中间节点 赋给起点 不断循环</span><br>        cout &lt;&lt; City[u] &lt;&lt; <span class="hljs-string">&quot;-&gt;&quot;</span>;<br>        u = Cway[u][ELoc];<br>    &#125;<br>    cout &lt;&lt; City[ELoc]&lt;&lt;endl;<br><br>    <span class="hljs-keyword">break</span>; <br>&#125;<br><span class="hljs-keyword">case</span> <span class="hljs-number">3</span>: &#123;<span class="hljs-keyword">break</span>; &#125;<br>   <br><span class="hljs-keyword">case</span> <span class="hljs-number">4</span>: &#123;<span class="hljs-keyword">break</span>; &#125;<br>&#125;<br></code></pre></td></tr></table></figure>


<h2 id="Allpath："><a href="#Allpath：" class="headerlink" title="Allpath："></a>Allpath：</h2><p> <img src="https://imgbed.cheney.cc/picgo/8fe6974243d8440787fa12ab57f14854-20220405210353523.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>假设我们要找出结点3到结点6的所有路径，那么，我们就设结点3为起点，结点6为终点。我们需要的存储结构有：一个保存路径的栈、一个保存已标记结点的数组，那么找到结点3到结点6的所有路径步骤如下：<br>    1、 我们建立一个存储结点的栈结构，将起点3入栈，将结点3标记为入栈状态；<br>    2、 从结点3出发，找到结点3的第一个非入栈状态的邻结点1，将结点1标记为入栈状态；<br>    3、 从结点1出发，找到结点1的第一个非入栈状态的邻结点0，将结点0标记为入栈状态；<br>    4、 从结点0出发，找到结点0的第一个非入栈状态的邻结点2，将结点2标记为入栈状态；<br>    5、 从结点2出发，找到结点2的第一个非入栈状态的邻结点5，将结点5标记为入栈状态；<br>    6、 从结点5出发，找到结点5的第一个非入栈状态的邻结点6，将结点6标记为入栈状态；<br>    7、 栈顶结点6是终点，那么，我们就找到了一条起点到终点的路径，输出这条路径；<br>    8、 从栈顶弹出结点6，将6标记为非入栈状态；<br>    9、 现在栈顶结点为5，结点5没有除终点外的非入栈状态的结点，所以从栈顶将结点5弹出；<br>    10、现在栈顶结点为2，结点2除了刚出栈的结点5之外，还有非入栈状态的结点6，那么我们将结点6入栈；<br>    11、现在栈顶为结点6，即找到了第二条路径，输出整个栈，即为第二条路径<br>    12、重复步骤2-11，就可以找到从起点3到终点6的所有路径；<br>    13、栈为空，算法结束。</p>
<p><strong>路径的存储：</strong><br>CCListHead[i]-&gt;data 是第i条路径的长度 CCListHead[i]-&gt;next-&gt;data等是路径上的节点 ;<br>排序：CCListHead[i]（0~n）用快速排序进行排序</p>
<h2 id="快排算法："><a href="#快排算法：" class="headerlink" title="快排算法："></a>快排算法：</h2><p>快速排序（改进版）（交换排序的一种）<br><strong>递归快排：</strong><br>改进方案：改进选取枢轴的方法，即每次选取数据集中的中位数做枢轴，（选取中位数的可以在 O(n)时间内完成）。<br><strong>快排的分割策略：</strong><br>第一步是通过将枢轴元与最后一个元素交换使得枢轴元离开要被分割的数据段；i 从第一个元素开始而 j 从倒数第二个元素开始。当 i 在 j 左边时，我们将 i 右移，移过那些小于枢轴元的元素，并将 j 左移，移过那些大于枢轴元的元素。当 i 和 j 停止时，i 指向的是大元素，j指向的是小元素。如果 i 在 j 左边，那么将这两个元素互换。 如果此时 i 和 j 已经交错即 i&gt;j所以不交换。此时把枢轴元与 i 所指的元素交换。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//返回中位数位置</span><br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">GetMiddleValue</span><span class="hljs-params">(<span class="hljs-type">int</span> A[], <span class="hljs-type">int</span> low, <span class="hljs-type">int</span> high)</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-comment">//  int mid = low + (high - low) &gt;&gt; 1;</span><br>    <span class="hljs-type">int</span> mid = (high + low) / <span class="hljs-number">2</span>;<br><br>    <span class="hljs-type">int</span> y1 = A[low] &gt; A[mid] ? low : mid;<br>    <span class="hljs-type">int</span> y2 = A[low] &gt; A[high] ? low : high;<br>    <span class="hljs-type">int</span> y3 = A[mid] &gt; A[high] ? mid : high;<br><br>    <span class="hljs-keyword">if</span> (y1 == y2) <span class="hljs-keyword">return</span> y3;<br><br>    <span class="hljs-keyword">else</span> <span class="hljs-keyword">return</span> A[y1] &gt; A[y2] ? y2 : y1;<br>&#125;<br></code></pre></td></tr></table></figure>

<h2 id="CC-File2："><a href="#CC-File2：" class="headerlink" title="CC_File2："></a>CC_File2：</h2><p>先将文件“连接”读入到FilePath[][],0表示无连接，1表示有连接<br>再把文件“距离”读入到FilePath[][],若ij有连接则把FilePath[i][]改为文件中读到的权值，若ij无连接则保持FilePath[i][]为0即可。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-function">ifstream <span class="hljs-title">in_file</span><span class="hljs-params">(<span class="hljs-string">&quot;省会城市邻接表.txt&quot;</span>, ios::in)</span></span>;<br>      hang = <span class="hljs-number">2</span>;<span class="hljs-comment">//原文件第一行为空白</span><br>      <span class="hljs-keyword">while</span> (in_file)<br>      &#123;<br>          string s;<br>          <span class="hljs-built_in">getline</span>(in_file, s);<br>          <span class="hljs-type">int</span> lie = <span class="hljs-number">1</span>;<br>          <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; i &lt; s.<span class="hljs-built_in">length</span>(); i++)<br>          &#123;<br>              <span class="hljs-keyword">if</span> (s[i] != <span class="hljs-string">&#x27;,&#x27;</span>)<br>              &#123;<br>                  string c = <span class="hljs-string">&quot;&quot;</span>;<br>                  <span class="hljs-keyword">while</span> (s[i] != <span class="hljs-string">&#x27;,&#x27;</span>)<br>                  &#123;<br>                      <span class="hljs-keyword">if</span> (i &gt;= s.<span class="hljs-built_in">length</span>()) <span class="hljs-keyword">break</span>;<br>                      c += s[i];<br>                      i++;<br>                  <span class="hljs-comment">//    if (i &gt;= s.length()) break;</span><br>                  &#125;<br>                  <span class="hljs-keyword">if</span> (FilePath[hang][lie] == <span class="hljs-number">1</span> )<span class="hljs-comment">//1表示有连接</span><br>                  &#123;<br>                      FilePath[hang][lie] = <span class="hljs-built_in">stoi</span>(c.<span class="hljs-built_in">c_str</span>());<br>                      FilePath[lie][hang] = <span class="hljs-built_in">stoi</span>(c.<span class="hljs-built_in">c_str</span>());<br>                     <span class="hljs-comment">//InsertEdge(hang, lie, stoi(c.c_str()));</span><br>                   <span class="hljs-comment">//   lie++;</span><br>                  &#125;<br>                  lie++;<br>              &#125;<br>          &#125;<br>          hang++;<br>      &#125;<br>      in_file.<span class="hljs-built_in">close</span>();<br><br>      <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; i &lt;= <span class="hljs-number">34</span>; i++)<br>          <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> j = <span class="hljs-number">0</span>; j &lt;= <span class="hljs-number">34</span>; j++)<br>              <span class="hljs-keyword">if</span> (i == j)<br>                  FilePath[i][j] = <span class="hljs-number">0</span>;<br>          <br>  <br>      <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">1</span>; i &lt;= <span class="hljs-number">34</span>; i++) &#123;<br>          cout &lt;&lt; endl;<br>          <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> j = <span class="hljs-number">1</span>; j &lt;= <span class="hljs-number">34</span>; j++)<br>              cout &lt;&lt; FilePath[i][j] &lt;&lt; <span class="hljs-string">&quot;\t&quot;</span>;<br>      &#125;<br>      cout &lt;&lt; <span class="hljs-string">&quot;\n读取文件处理完毕\n&quot;</span>;<br></code></pre></td></tr></table></figure>

<h2 id="A-Star："><a href="#A-Star：" class="headerlink" title="A_Star："></a>A_Star：</h2><p>在A*算法中用优先队列就是要用到启发函数f(s)确定状态在优先队列里面的优先级。解决这道题的时候选取h(x)=dt(x), dt(x)是x节点到目标节点的最短距离，其开始由Dijkstra直接求得。<br>控制每个节点的入队（或出队）次数为k次，可以找到第k短路径。</p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-keyword">struct</span> <span class="hljs-title class_">a_star</span> <span class="hljs-comment">//A*搜索时的优先级队列</span><br>&#123;<br>    <span class="hljs-type">int</span> v;<span class="hljs-comment">//当前指示的节点</span><br>    <span class="hljs-type">int</span> len;<span class="hljs-comment">//到起点的距离</span><br>    <span class="hljs-type">bool</span> <span class="hljs-keyword">operator</span>&lt;(<span class="hljs-type">const</span> a_star&amp; a)<span class="hljs-type">const</span>    <span class="hljs-comment">//f(i)=d[i]+h[i] h(i)表示i到end的最短路(储存在dis[]中，由djikstra给出)</span><br>    &#123;<br>        <span class="hljs-keyword">return</span> len + dis[v] &gt; a.len + dis[a.v];<span class="hljs-comment">//len + dis[v]值小的 在优先级队列里面有更高的优先级</span><br>    &#125;<br>&#125;;<br><span class="hljs-function"><span class="hljs-type">int</span> <span class="hljs-title">C_Astar</span><span class="hljs-params">(<span class="hljs-type">int</span> Path[MaxSize][MaxSize],<span class="hljs-type">int</span> N,<span class="hljs-type">int</span> Begin ,<span class="hljs-type">int</span> End ,<span class="hljs-type">int</span> K,<span class="hljs-type">int</span> ans[MaxSize])</span></span><br><span class="hljs-function"></span>&#123;<br>    <span class="hljs-keyword">if</span> (Begin == End)<br>        K++;<br>    <span class="hljs-keyword">if</span> (dis[Begin] == MaxNum) &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;<br>    &#125;<br><br>    a_star n1;<span class="hljs-comment">//a_star</span><br>    n1.v = Begin;<br>    n1.len = <span class="hljs-number">0</span>;<br>    priority_queue &lt;a_star&gt; q;<span class="hljs-comment">//优先级队列</span><br>    q.<span class="hljs-built_in">push</span>(n1);<span class="hljs-comment">//初始状态 起点入队</span><br>    <span class="hljs-keyword">while</span> (!q.<span class="hljs-built_in">empty</span>())<br>    &#123;<br>        a_star temp = q.<span class="hljs-built_in">top</span>();<span class="hljs-comment">//temp是当前有最大优先级的元素</span><br>        q.<span class="hljs-built_in">pop</span>();<br>        ans[temp.v]++;<span class="hljs-comment">//计数器，表示v节点访问次数加一</span><br>        <span class="hljs-keyword">if</span> (ans[End] == K)<span class="hljs-comment">//当第K次取终点的时候，输出路程</span><br>            <span class="hljs-keyword">return</span> temp.len;<br>        <span class="hljs-keyword">if</span> (ans[temp.v] &gt; K)<span class="hljs-comment">//v已经入队k次 则直接 跳过</span><br>            <span class="hljs-keyword">continue</span>;<br><br>        <span class="hljs-type">int</span> i = temp.v;<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> j = <span class="hljs-number">0</span>; j &lt; N; j++)<br>         <span class="hljs-keyword">if</span> (Path[i][j] != <span class="hljs-number">0</span>) &#123;<span class="hljs-comment">//遍历所有与i有连接的点j</span><br>            a_star n2;<br>            n2.v = j;<br>            n2.len = Path[i][j] + temp.len;<br>            q.<span class="hljs-built_in">push</span>(n2);<br>         &#125;<br><br>    &#125;<br>    <span class="hljs-keyword">return</span> <span class="hljs-number">-1</span>;<br>&#125;<br></code></pre></td></tr></table></figure>


<h2 id="所有路径结果写入文件："><a href="#所有路径结果写入文件：" class="headerlink" title="所有路径结果写入文件："></a>所有路径结果写入文件：</h2><p> <img src="https://imgbed.cheney.cc/picgo/0c0016078650499d8ee80775ff9e4fe6-20220405210353590.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs cpp"><span class="hljs-comment">//输出文件格式 ：序号，长度，A-&gt;B-&gt;C-&gt;end;</span><br>   ofstream out;<br>   out.<span class="hljs-built_in">open</span>(<span class="hljs-string">&quot;结果.txt&quot;</span>);<br>   <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> i = <span class="hljs-number">0</span>; i &lt; PathNum; i++)<br>   &#123;<br>       LinkList* p = CCListHead[i];<br>       out &lt;&lt; i + <span class="hljs-number">1</span> &lt;&lt; <span class="hljs-string">&quot;:--长&quot;</span> &lt;&lt; p-&gt;Data &lt;&lt; <span class="hljs-string">&quot;    &quot;</span>;<br>       p = p-&gt;next;<br>       <span class="hljs-keyword">while</span> (p-&gt;next!= <span class="hljs-literal">NULL</span>)<br>       &#123;<br>           out &lt;&lt; City[p-&gt;Data] &lt;&lt; <span class="hljs-string">&quot;-&gt;&quot;</span>;<br>           p = p-&gt;next;<br>       &#125;<br>       out &lt;&lt; City[p-&gt;Data] &lt;&lt; endl;<br>   &#125;<br>   out.<span class="hljs-built_in">close</span>();<br></code></pre></td></tr></table></figure>

<h1 id="五、用户手册："><a href="#五、用户手册：" class="headerlink" title="五、用户手册："></a>五、用户手册：</h1><p> 打开程序后会显示菜单和城市信息，选择需要的功能输入即可，注意本程序输入的城市是城市对应的编号（菜单给出对应关系）而不是城市名称。</p>
<ul>
<li>功能一：选择此功能可以验证全国任一城市到其他所有城市之间的城市数，如果要验证题目中所述即全国其他省会城市（不包括港澳和两个宝岛台北和海口）到武汉中间不超过 2 个省，只需输入编号22即可。</li>
<li>功能二：选择此功能后需要再输入待求的两个城市的编号，程序会自动输出三种算法算出的最短路径长度和路线，并输出两座城市间所有不重复的可行路径（最多经过 10 个节点）以及所有路径的数量，排序后程序输出前十五条短的路径，并将所有路径信息写入文件。 </li>
</ul>
<h1 id="六、测试结果："><a href="#六、测试结果：" class="headerlink" title="六、测试结果："></a>六、测试结果：</h1><p> <img src="https://imgbed.cheney.cc/picgo/dc6f161bd5b0449cb6e3dcaf5fa64d4f-20220405210353637.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>表 1 功能一<br><img src="https://imgbed.cheney.cc/picgo/6638c20af958464cb9c24fc7f59a7ec2-20220405210353681.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>表 2 功能二<br> <img src="https://imgbed.cheney.cc/picgo/9a526f8b29264287be3e1be181286c2b-20220405210353726.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>表 3 功能三<br> <img src="https://imgbed.cheney.cc/picgo/8ee77e91fce840489893a0c6e53db096-20220405210353769.png" srcset="/img/loading.gif" lazyload alt="在这里插入图片描述"></p>
<p>表 4 功能四</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/">数据结构</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/C/">C++</a>
                    
                      <a class="hover-with-bg" href="/tags/%E5%9B%BE/">图</a>
                    
                      <a class="hover-with-bg" href="/tags/Dijkstra/">Dijkstra</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/04/05/%E7%BC%96%E8%AF%91%E5%8E%9F%E7%90%86__%E7%B1%BB%20Pascal%E8%AF%AD%E8%A8%80%E8%AF%8D%E6%B3%95%E5%88%86%E6%9E%90%E5%AE%9E%E9%AA%8C%EF%BC%88%E7%AE%80%E6%98%93%E7%89%88%EF%BC%89/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">类 Pascal语言词法分析实验（简易版）</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/08/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%AE%9E%E9%AA%8C--%E5%94%AF%E4%B8%80%E7%9A%84%E7%A1%AE%E5%AE%9A%E4%B8%80%E6%A3%B5%E4%BA%8C%E5%8F%89%E6%A0%91/">
                        <span class="hidden-mobile">唯一的确定一棵二叉树</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://cheney822.gitee.io/" target="_blank" rel="nofollow noopener"><span>备用网址</span></a> 
  </div>
  

  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        皖ICP备2022002876号-1
      </a>
    </span>
    
  </div>


  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  






  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>















<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
